package monopoli.communication;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Marco
 */
public class SynchronizerPlayer {

    //Attributes
    private int players;
    private int min_players;
    private int max_players;


    //Constructor
    public SynchronizerPlayer(int min_players, int max_players) {
        this.players = 0;

        this.min_players = min_players;
        this.max_players = max_players;
    }


    //Public Methods
    public synchronized boolean enterPlayer() {

        players++;

        if (players < max_players) {
            try {
                wait();
            } catch (InterruptedException ex) {
                Logger.getLogger(SynchronizerPlayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (players == max_players) {
            notifyAll();
        }

        return true;
    }

    public synchronized boolean exitPlayer() {

        return true;
    }
}
